import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //登录显示
    isOpenLogin: false,
    //提示框
    toast: {
      show: false,
      content: "你好",
      icon: "icon-toast_chenggong"
    },


    // 当前播放的音乐
    music: {},

    //搜索
    TxtVal: ''

  },
  getters: {
  },
  mutations: {
    // //修改搜索
    // chagesearch(state, payload) {
    //   state.TxtVal = payload
    // },
    // 修改登录框状态的方法
    changeIsShowLogin(state, payload) {
      state.isOpenLogin = payload
    },
    // 打开提示组件Toast
    openToast(state, payload) {
      state.toast.show = true,
        state.toast.content = payload.content;
      switch (payload.icon) {
        case "info":
          state.toast.icon = "icon-toast-jinggao";
          break;
        case "success":
          state.toast.icon = "icon-toast_chenggong";
          break;
        case "danger":
          state.toast.icon = "icon-toast-shibai_huaban";
          break;
        case "loading":
          state.toast.icon = "icon-loading";
          break;
        default:
          state.toast.icon = "icon-toast-jinggao";
          break;
      }

    },
    // 同步关闭toast
    closeToast(state) {
      state.toast.show = false
    },
    // 设置当前播放的音乐
    SetMusic(state, music) {
      state.music = music || {};
    },

  },
  actions: {
    // 关闭提示框
    AsyncToast({
      commit
    }, payload) {
      console.log(1);
      commit('openToast', payload);
      setTimeout(() => {
        commit('closeToast')
      }, 2000)
    },
    // 设置当前播放的音乐
    setMusics({ commit }, id) {
      setMusic(id);
      let result = reqSong(id, localStorage.getItem('COOKIE'));
      commit('SetMusic', result.songs[0])
    },
    // 获取当前播放的音乐
    getMusics({ commit }) {
      let result = reqSong(getMusic(), localStorage.getItem('COOKIE'));
      commit('SetMusic', result.songs[0])
    }

  },
  modules: {
  }
})
